package com.example.docker.controller;

import cn.hutool.core.util.IdUtil;
import com.example.docker.bean.User;
import com.example.docker.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

@RestController
public class DemoController {
    @Autowired
    UserService userService;

    @ApiOperation("数据库新增3条记录")
    @RequestMapping(value = "/user/add",method = RequestMethod.POST)
    public void addUser()
    {
        for (int i = 1; i <=3; i++) {
            User user = new User();

            user.setUsername("wangtc_0"+i);
            user.setPassword(IdUtil.simpleUUID().substring(0,6));
            user.setSex((byte) new Random().nextInt(2));
            user.setDeleted(new Byte((byte) 0));

            userService.addUser(user);
        }
    }

    @ApiOperation("删除1条记录")
    @RequestMapping(value = "/user/delete/{id}",method = RequestMethod.POST)
    public void deleteUser( Integer id)
    {
        userService.deleteUser(id);
    }

    @ApiOperation("查询1条记录")
    @RequestMapping(value = "/user",method = RequestMethod.GET)
    public User getUser( Integer id)
    {
       return  userService.findUserById(id);
    }
}
